<?php $formatter = new sfNumberFormat($sf_user->getCulture())?>
<?php
print link_to('<img title="'.__('Input Turnover').'" src="/images/icons/48/calculator.png"></img>', 'chiffres/input?id='. $self->id);
?>

<fieldset><legend><?php echo __('Totaux')?></legend>
<?php $q = Doctrine_Query::create()
		->select('ic.id, p.description')
		->addSelect('sum(ic.chiffre) as chiffre')
		->from('item_chiffre_affaires ic')
		->innerJoin('ic.produit p')
		->where('ic.owner_id = ?', $self->id)
		->groupBy('p.description');
		$q->setHydrationMode(Doctrine::HYDRATE_ARRAY);
		$records = $q->execute();?>
		<table>
		<thead><tr><th>Produit</th><th>Chiffre</th></tr>
		</thead>
		<tbody>
		<?php 
		foreach ($records as $item_chiffre) :
		?>	
		<tr>
		<td><?php echo $item_chiffre['produit']['description']?></td>
		<td><?php echo $formatter->format($item_chiffre['chiffre'], 'd'); ?></td>
		<?php $total += $item_chiffre['chiffre']?>
		</tr>
		<?php 
		endforeach;?>
		
		</tbody>	
		<tfoot><tr>
		<th>Total</th><th><?php echo $formatter->format($total,  'd')?></th>
		</tr></tfoot>
		</table>
			

</fieldset>